#ifndef ROADITEM_H
#define ROADITEM_H

#include <vector>

#include <QList>
#include <QGraphicsItemGroup>
#include <QPainter>
#include <QStyleOptionGraphicsItem>
#include <QWidget>
#include <QGraphicsSceneMouseEvent>

#include "lane.h"
#include "commondefine.h"
#include "laneitem.h"
#include "roaddata.h"

using std::vector;


class RoadItem: public QObject, public QGraphicsItemGroup
{
    //如果需要信号和槽，必须继承QObject
    Q_OBJECT

public:
    RoadItem()
    {
        setHandlesChildEvents(false);
        m_bShowRoad = false;
    }

    RoadItem(vector<Lane> &vecLane, QPolygonF &qpolygonPoint);

    RoadItem(const RoadItem &rdItem)
    {
        this->m_vecLane = rdItem.m_vecLane;
        this->m_qpolygonPoint = rdItem.m_qpolygonPoint;
    }

    RoadItem &operator = (const RoadItem &rdItem)
    {
        this->m_vecLane = rdItem.m_vecLane;
        this->m_qpolygonPoint = rdItem.m_qpolygonPoint;
    }

    ~RoadItem();

    void parseData();

    QPainterPath shape() const Q_DECL_OVERRIDE;

    virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override;

    QString getId() const;
    void setId(const QString &qstrId);
    QString getType() const;
    void setType(const QString &qstrType);
    void setLaneLine(const QList<QPolygonF> &qlstLaneLine);
    void appendLaneLine(const QPolygonF &polygon);
    void appendLaneItem(LaneItem *pLaneItem);
    void appendLane(const SLane &lane);
    void setObject(const QVector<Object> &qvecObject);
    void setPolygonPoint(const QPolygonF &qpolygonPoint);
    QVector<SElevation> getElevations() const;
    void setElevations(const QVector<SElevation> &qvecElevation);
    void appendElevation(const SElevation &elevation);
    QVector<SLaneOffset> getLaneOffsets() const;
    void setLaneOffsets(const QVector<SLaneOffset> &qvecLaneOffset);
    void appendLaneOffset(const SLaneOffset &laneOffset);

protected:
    virtual void mousePressEvent(QGraphicsSceneMouseEvent *event) override;

private:
    vector<SLane> m_vecLane;
    QVector<Object> m_qvecObject;
    QVector<SElevation> m_qvecElevation;
    QVector<SLaneOffset> m_qvecLaneOffset;
    QList<LaneItem*> m_qlstLaneItem;
    QList<QPolygonF> m_qlstLaneLine;
    QPolygonF m_qpolygonPoint;
    QString m_qstrId;
    QString m_qstrType;
    bool m_bShowRoad;

public slots:
    void onRoad(LaneItem *pLaneItem, const QPointF &pointf);
    void onClick();

signals:
    void sigRoad(RoadItem *, LaneItem *, const QPointF &pointf);
};

#endif // ROADITEM_H
